package cn.donting.jme.expansion.attribute;


import cn.donting.jme.swing.JKeyValuePanel;
import cn.donting.jme.swing.JTitlePane;
import cn.donting.jme.swing.layout.Anchor;
import org.checkerframework.checker.units.qual.A;
import org.jdesktop.swingx.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class TitlePaneAttributeGroup extends AttributeGroup {

    private JTitlePane jTitlePane = new JTitlePane();

    public TitlePaneAttributeGroup(String title) {
        setTitle(title);
        setShowEnabled(false);
    }

    public void setShowEnabled(boolean showEnabled) {
        jTitlePane.setShowEnabled(showEnabled);
    }

    public void setEnabled(boolean enabled) {
        jTitlePane.setEnabled(enabled);
    }

    public void setEnabledValueChange(ValueChangeListener<Boolean> enabledValueChange) {
        jTitlePane.setEnabledValueChange(enabledValueChange);
    }

    public void setTitleIcon(Icon icon) {
        jTitlePane.setTitleIcon(icon);
    }

    public void setTitle(String title) {
        jTitlePane.setTitle(title);
    }

    public Container getContentPanel(){
        return jTitlePane.getContentPanel();
    }

    public void setExpand(boolean expand){
        jTitlePane.setExpand(expand);
    }

    public void addAttribute(Attribute attribute){
        super.addAttribute(attribute);
        if(attribute instanceof KeyValueAttribute){
            JKeyValuePanel contentPanel = jTitlePane.getContentPanel();
            contentPanel.add(((KeyValueAttribute) attribute).getKeyComponent(),((KeyValueAttribute) attribute).getValueComponent());
        }else {
            Container contentPanel = jTitlePane.getContentPanel();
            contentPanel.add(attribute.getUIContainer());
        }
    }

    @Override
    public void clear() {
        super.clear();
        Container contentPanel = jTitlePane.getContentPanel();
        contentPanel.removeAll();
    }

    @Override
    public Container getUiContainer() {
        return jTitlePane;
    }

    @Override
    public String toString() {
        return jTitlePane.getTitle();
    }
}
